package com.toponed.frame;

import com.toponed.event.BeginEvent;

import javax.swing.*;
import java.awt.*;

public class Window extends JFrame {
    int side = 3;
    String[] names = {"酸菜鱼", "蒸菜", "湘菜馆", "便利峰", "开始", "麻辣烫", "牛肉面", "外卖", "毛血旺"};
    JButton[] jbs = new JButton[side * side];

    boolean begin = false;


    public Window() {
        initJButton();
        this.setLayout(new GridLayout(side, side));
        this.setSize(400, 400);
        this.setLocation(600, 400);
        this.setVisible(true);
        this.setTitle("点餐老虎机");
    }

    private void initJButton() {
        for (int i = 0; i < jbs.length; i++) {
            jbs[i] = defaultButton(i);
            if (i == 0) {
                jbs[i].setBackground(Color.RED);
            }
            jbs[i].setOpaque(true);
            this.add(jbs[i]);
        }
    }

    private JButton defaultButton(int i) {
        JButton jButton = new JButton(String.valueOf(i));
        jButton.setBackground(new Color(0xFFFFFF));
        jButton.setText(names[i]);
        if (i == 4) {
            jButton.addMouseListener(new BeginEvent(begin, side, side, jbs));
            jButton.setBackground(Color.GRAY);
        }
        return jButton;
    }
}
